<template>
  <div class="KeyPersonnel card-bg">
    <div class="card-title">重点/关爱人员</div>
    <div class="content">
      <div class="left">
        <div class="item" v-for="(item, index) in keyPersonList" :key="index">
          <div>
            <span
              class="rect"
              :style="`background: ${item.colorValue};`"
            ></span>
            <span class="name">{{ item.name }}</span>
          </div>
          <div>
            {{ item.value }}
            人
          </div>
        </div>
      </div>
      <div class="right">
        <p>重点人员抓拍图像</p>
        <div style="width: 160px">
          <img :src="image" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { statisticsKeyPerson } from "@/api/panoramicData";
let timer = null;
export default {
  created() {
    this.runStatisticsKeyPerson();
  },
  beforeDestroy() {
    timer && clearInterval(timer);
  },
  data() {
    return {
      image: "",
      keyPersonList: [
        { name: "在逃人员", value: 0, colorValue: "#22c8d0" },
        { name: "涉稳人员", value: 0, colorValue: "#0b5bfd" },
        { name: "涉毒人员", value: 0, colorValue: "#ccbd80" },
        { name: "前科人员", value: 0, colorValue: "#ce65a4" },
        { name: "两失人员", value: 0, colorValue: "#c13a9d" },
        { name: "上访人员", value: 0, colorValue: "#3fc23d" },
        { name: "精神病人员", value: 0, colorValue: "#cfa038" },
      ],
    };
  },
  methods: {
    async runStatisticsKeyPerson() {
      const res = await statisticsKeyPerson();
      this.keyPersonList[0].value = res.data.Group[0].Value;
      this.keyPersonList[1].value = res.data.Group[1].Value;
      this.keyPersonList[2].value = res.data.Group[2].Value;
      this.keyPersonList[3].value = res.data.Group[3].Value;
      this.keyPersonList[4].value = res.data.Group[4].Value;
      this.keyPersonList[5].value = res.data.Group[5].Value;
      this.keyPersonList[6].value = res.data.Group[6].Value;
      this.image = res.data.Image;

      timer = setInterval(() => {
        statisticsKeyPerson().then((res) => {
          this.keyPersonList[0].value = res.data.Group[0].Value;
          this.keyPersonList[1].value = res.data.Group[1].Value;
          this.keyPersonList[2].value = res.data.Group[2].Value;
          this.keyPersonList[3].value = res.data.Group[3].Value;
          this.keyPersonList[4].value = res.data.Group[4].Value;
          this.keyPersonList[5].value = res.data.Group[5].Value;
          this.keyPersonList[6].value = res.data.Group[6].Value;
          this.image = res.data.Image;
        });
      }, 300000);
    },
  },
};
</script>
<style lang="scss" scoped>
.KeyPersonnel {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;

  .content {
    width: 100%;
    height: calc(100% - 50px);
    display: flex;

    .left,
    .right {
      width: 50%;
      height: 100%;
    }

    .left {
      flex-direction: column;
      display: flex;
      justify-content: space-around;
    }

    .item {
      color: #d6d6d8;
      color: #d6d6d8;
      display: flex;
      justify-content: space-around;

      .rect {
        display: inline-block;
        width: 16px;
        height: 10px;
        padding-right: 4px;
        margin-right: 4px;
      }

      .name {
      }
    }

    .right {
      text-align: center;

      p {
        color: #8aadcf;
        font-size: 14px;
      }
    }
  }
}
</style>
